﻿/*
 * Exception.h
 */

#ifndef __GDK_EXCEPTION_H__
#define __GDK_EXCEPTION_H__


#include <gdk/core/Types.h>
#include <gdk/core/CallStack.h>
#include <string>



namespace gdk
{


class GDK_CORE_EXPORT Exception
{
private:
#if defined(_UNICODE)
	typedef std::wstring	string;
#else
	typedef std::string		string;
#endif

private:
	string	_fileName;
	int		_line;
	string	_function;
	string	_description;

#if defined(_WIN32)
	CallStack*	_callStack;
#endif

public:
	~Exception(void);
	Exception(
		Char const *fileName,
		int        line,
		Char const *function,
		Char const *description
	);
	Exception(Exception const &e);
	Exception& operator =(Exception const &e);

	__INLINE__ const Char* file(void) const { return _fileName.c_str(); }
	__INLINE__ int line(void) const { return _line; }
	__INLINE__ const Char* function(void) const { return _function.c_str(); }
	__INLINE__ const Char* description(void) const { return _description.c_str(); }

	void report(void) const;
};




#ifdef _WIN32

#	define __TRY					try
#	define __CATCH(...)				catch(gdk::Exception const &__VA_ARGS__)
#	define __THROW1					throw(...)
#	define __THROW__(description)	throw gdk::Exception(__GDK_FILE__, __LINE__, __GDK_FUNCTION__, description)

#else

#	define __TRY					try
#	define __CATCH(...)				catch(gdk::Exception const &__VA_ARGS__)
#	define __THROW1
#	define __THROW__(description)	throw gdk::Exception(__GDK_FILE__, __LINE__, __GDK_FUNCTION__, description)

#endif




}//namespace gdk




#endif //__GDK_EXCEPTION_H__
